<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <th:block th:insert="~{/common/include_assets :: include_assets}"></th:block>
    <th:block th:insert="~{/common/include_easyui_only :: include_easyui_only}"></th:block>
    <title>权限管理系统</title>
    <style>
        .west {
            width: 200px;
            padding: 10px;
        }

        .footer {
            text-align: center;
            color: #15428B;
            margin: 0px;
            padding: 0px;
            line-height: 22px;
            background: #D2E0F2;
        }

        .panel-body {
            padding: 0px;
            overflow: hidden;
        }

        #footer.panel-body, #header.panel-body, #content.panel-body {
            border: none;
        }

    </style>
</head>
<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
<div id="header" region="north" split="false" border="false" style="overflow: hidden; height: 60px;
        line-height: 20px;color: #fff;" th:insert="~{header::header}">
</div>

<div region="center" id="content">
    <div class="easyui-tabs" border="false" id="tabs" data-options="tabWidth:160,fit:true">
        <div title="首页" style="overflow:hidden;" id="home">
            <iframe scrolling="auto" frameborder="0" style="width:100%;height:100%;overflow-x:hidden "
            th:src="@{/mainController/welcomePage}"></iframe>
        </div>
    </div>
</div>


<div region="west" class="west" title="导航菜单" style="padding: 0px;margin: 0px;">
    <!--默认树形菜单-->
    <ul id="div_tree"
        th:if="${null==#session.getAttribute('configParam') or #session.getAttribute('configParam').leftMenu=='tree'}"></ul>
    <!--可折叠菜单-->
    <div class="easyui-accordion" data-options="fit:true"
         th:if="${null!=#session.getAttribute('configParam') and #session.getAttribute('configParam').leftMenu!='tree'}">
        <div th:title="${rowMap.text}" icon="icon-sys" style="overflow: auto;" th:each="rowMap:${parentList}">
            <div th:id="${'div_tree_'+ rowMap.id}"></div>
        </div>
    </div>
</div>

<div id="footer" region="south" border="false" split="false" style="height: 40px;" data-options="border:false"
     th:insert="~{footer::footer}">
</div>

<div id=mm class="easyui-menu" style="width:150px;">
    <div id="mm-tabclose">关闭</div>
    <div id="mm-tabcloseall">全部关闭</div>
    <div id="mm-tabcloseother">除此之外全部关闭</div>
    <div class="menu-sep"></div>
    <div id="mm-tabcloseright">当前页右侧全部关闭</div>
    <div id="mm-tabcloseleft">当前页左侧全部关闭</div>
    <div class="menu-sep"></div>
    <div id="mm-exit">退出</div>
</div>
<script th:inline="javascript">
    var ctxPath = /*[[${#httpServletRequest.getContextPath()}]]*/ "/as";
    $(function () {
        /*<![CDATA[*/
        var configParamStr = /*[[${configParamJson}]]*/ "{}";
        var parentListStr = /*[[${parentListJson}]]*/ "[]";

        var configParam = JSON.parse(configParamStr);
        var parentList = JSON.parse(parentListStr);

        if (configParam&&"accordion"==configParam.leftMenu) {// 可折叠菜单
            debugger
            if (parentList&&parentList.length>0) {
                //动态菜单数据
                for (var i = 0; i < parentList.length; i++) {
                    var rowMap = parentList[i];
                    var id = rowMap.id;
                    var loadURL = ctxPath+"/mainController/loadUserMenu?parentId=" + id + "";
                    //实例化树形菜单
                    jQuery("#div_tree_" + id + "").tree({
                        lines: true,
                        url: loadURL,
                        onClick: function (node) {
                            var isLeaf = node.isLeaf;
                            var menu_name = node.text;
                            var menu_href = ctxPath+node.menuHref;
                            //window.alert(menu_href);
                            if (isLeaf == 1) {
                                addTab(menu_name, menu_href, "icon-tip");
                            }
                        }
                    });
                }
            }
        }else{
            //树形菜单（默认
            //动态菜单数据
            var loadURL = ctxPath+"/mainController/loadUserMenu";
            //实例化树形菜单
            jQuery("#div_tree").tree({
                lines: true,
                url: loadURL,
                onClick: function (node) {
                    var isLeaf = node.isLeaf;
                    var menu_name = node.text;
                    var menu_href = ctxPath + node.menuHref;
                    //window.alert(menu_href);
                    if (isLeaf == 1) {
                        addTab(menu_name, menu_href, "icon-tip");
                    }
                }
            });
        }

        /*]]>*/
        function addTab(subtitle, url, icon) {
            if (!$('#tabs').tabs('exists', subtitle)) {
                $('#tabs').tabs('add', {
                    title: subtitle,
                    content: '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>',
                    closable: true,
                    iconCls: icon
                });
            } else {
                $('#tabs').tabs('select', subtitle);
            }
            tabClose();
        }

        function tabClose() {
            /*双击关闭TAB选项卡*/
            $(".tabs-inner").dblclick(function () {
                var subtitle = $(this).children(".tabs-closable").text();
                $('#tabs').tabs('close', subtitle);
            })
            /*为选项卡绑定右键*/
            $(".tabs-inner").bind('contextmenu', function (e) {
                $('#mm').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });

                var subtitle = $(this).children(".tabs-closable").text();

                $('#mm').data("currtab", subtitle);
                $('#tabs').tabs('select', subtitle);
                return false;
            });
        }

        //绑定右键菜单事件

        $("#editPersonInfoBtn").click(function () {
            var editURL = ctxPath + "/userPersonalController/preModifyPersonalInfo?date=" + new Date() + "";
            addTab("修改信息", editURL, "icon-tip");
        });
        $("#modifyPwdBtn").click(function () {
            var modifyURL = ctxPath + "/userPersonalController/preModifyPersonalPwd?date=" + new Date() + "";
            addTab("修改密码", modifyURL, "icon-tip");
        });
        $("#logoutBtn").click(function () {
            $.messager.confirm('注销提示', '您确认要退出系统吗？', function (tag) {
                if (tag) {
                    location.href = ctxPath + "/securityController/logout";
                }
            });

        });


        //关闭当前
        $('#mm-tabclose').click(function () {
            var currtab_title = $('#mm').data("currtab");
            $('#tabs').tabs('close', currtab_title);
        })
        //全部关闭
        $('#mm-tabcloseall').click(function () {
            $('.tabs-inner span').each(function (i, n) {
                var t = $(n).text();
                if (t != "首页") {
                    $('#tabs').tabs('close', t);
                }

            });
        });
        //关闭除当前之外的TAB
        $('#mm-tabcloseother').click(function () {
            var currtab_title = $('#mm').data("currtab");
            $('.tabs-inner span').each(function (i, n) {
                var t = $(n).text();
                if (t != "首页") {
                    if (t != currtab_title)
                        $('#tabs').tabs('close', t);
                }
            });
        });
        //关闭当前右侧的TAB
        $('#mm-tabcloseright').click(function () {
            var nextall = $('.tabs-selected').nextAll();
            if (nextall.length == 0) {
                //msgShow('系统提示','后边没有啦~~','error');
                alert('后边没有啦~~');
                return false;
            }
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != "首页") {
                    $('#tabs').tabs('close', t);
                }
            });
            return false;
        });
        //关闭当前左侧的TAB
        $('#mm-tabcloseleft').click(function () {
            var prevall = $('.tabs-selected').prevAll();
            if (prevall.length == 0) {
                alert('到头了，前边没有啦~~');
                return false;
            }
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();

                if (t != "首页") {
                    $('#tabs').tabs('close', t);
                }
            });
            return false;
        });

        //退出
        $("#mm-exit").click(function () {
            $('#mm').menu('hide');
        })
    });
</script>
</body>
</html>